package com.journey.org.ui.home.bilivideo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.material.tabs.TabLayout
import com.journey.org.BR
import com.journey.org.R
import com.journey.org.databinding.FragmentBiliVideoBinding
import com.journey.org.ui.video.movie.MovieFragment
import com.journey.org.ui.video.recommend.RecommendFragment
import com.journey.org.ui.video.small.SmallVideoFragment
import com.mvvmhabit.org.base.BaseFragment
import com.mvvmhabit.org.base.BaseFragmentPagerAdapter
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerManager

/**
 * @Date: 2021/5/27 15:57
 * @Author:小妖
 * @Description:B站视频
 */
class BiliVideoFragment : BaseFragment<FragmentBiliVideoBinding, BiliVideoViewModel>() {


    private val mFragment = ArrayList<Fragment>()

    private val mTitle = ArrayList<String>()

    override fun initVariableId(): Int = BR.viewModel

    override fun initViewModel(): Class<BiliVideoViewModel> = BiliVideoViewModel::class.java

    override fun initContentView(
        inflater: LayoutInflater?,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): Int = R.layout.fragment_bili_video

    override fun initData() {
        super.initData()
        mFragment.add(RecommendFragment())
        mTitle.add("推荐")

        mFragment.add(MovieFragment())
        mTitle.add("影视资源")

        mFragment.add(SmallVideoFragment())
        mTitle.add("小视频")
        initAdapter()
    }

    private fun initAdapter() {
        //  mBinding.layoutVideoViewpager.offscreenPageLimit = 3
        val adapter = BaseFragmentPagerAdapter(activity!!.supportFragmentManager, mFragment, mTitle)
        mBinding.layoutBiliViewpager.adapter = adapter
        mBinding.layoutBiliTab.setupWithViewPager(mBinding.layoutBiliViewpager)
        mBinding.layoutBiliViewpager.addOnPageChangeListener(
            TabLayout.TabLayoutOnPageChangeListener(
                mBinding.layoutBiliTab
            )
        )
    }

}